import History from './base'

const ensureSlash = () => {
  if(window.location.hash) {
    return
  }
  window.location.hash = '/'
}

export default class HashHistory extends History {
  constructor(router) {
    super(router)
    // this.router = router
    // 默认跳转到首页
    ensureSlash()
  }
  getCurrentLocation() {
    return window.location.hash.slice(1)
  }
  setupListener() {
    window.addEventListener('hashchange', ()=>{
      console.log('hash 变化')
      this.transitionTo(this.getCurrentLocation())
    })
  }
}